(function(global){
    global.TRCKR = global.TRCKR || {};

    global.TRCKR.trackerController = function(){
        var tracking = false;
        var model = global.TRCKR.trackerModel();
        var cb = function(tabid){
            chrome.tabs.get(tabid, function(tab){
                model.addEntry(TRCKR.getDomainFromUrl(tab.url) || "other");
            });
        };
        var start = function(){
            chrome.tabs.onSelectionChanged.addListener(cb);
            chrome.tabs.onUpdated.addListener(cb);
        };
        var stop = function(){
        	chrome.tabs.onSelectionChanged.removeListener();
            chrome.tabs.onUpdated.removeListener();
        };
        var toggle = function(){
            tracking ? stop() : start();
            return tracking = !tracking;
        };
        return {
            toggle: toggle
        }
    };
})(this);